window.addEventListener('DOMContentLoaded', () => {
  console.log(window.location.host)

  const {ipcRenderer} = require('electron')
  //file system 文件系统
  const fs = require('fs')

  const Store = require('electron-store');
  const store = new Store();

  var sep = ''
  if (process.platform == 'darwin') {
    sep = '/'
  }else{
    sep = '\\'
  }

  // 把源代码写入html.txt文件
  fs.writeFile(store.get("baseDir") + sep + 'html.txt', document.documentElement.outerHTML, 'utf8' ,function(error){
      if(error){
          console.log(error);
          return false;
      }
      console.log('文件写入成功');
  })

  //发送源码给python爬虫，ipc通讯：开启python爬虫(发送给主进程main.js)
  ipcRenderer.send("start-python-crawl", {site:window.location.host,html:store.get("baseDir")+sep+'html.txt'});

  ipcRenderer.on("start-python-crawl-reply", (event, message) => {
      window.close()
  });
})
